<template>
  <div>
    <a-modal
      centered
      :title="title"
      :width="900"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      cancelText="关闭">

      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="10" :sm="8">
              <a-form-item label="规则名称">
                <a-input placeholder="请输入规则名称" v-model="queryParam.ruleName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>

      <!-- table区域-begin -->
      <div>
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onSelectAll:onSelectAll, onSelect:onSelect, onChange: onSelectChange}"
          @change="handleTableChange">
          <span slot="delFlag" slot-scope="text">
            <span v-if="text==0">有效</span>
            <span v-if="text==1">无效</span>
          </span>
        </a-table>
      </div>
    </a-modal>
  </div>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin.js'
  import { api } from '../service'

  export default {

    name: 'SelectDataRuleModal',
    mixins: [JeecgListMixin],
    components: {
      
    },
    data() {
      return {
        title: '选择已有数据规则',
        visible: false,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
           {
            title: '规则名称',
            dataIndex: 'ruleName',
            key: 'ruleName'
          },
          {
            title: '规则字段',
            dataIndex: 'ruleColumn',
            key: 'ruleColumn'
          },
          {
            title: '规则值',
            dataIndex: 'ruleValue',
            key: 'ruleValue'
          },

           {
            title: '状态',
            align: 'center',
            width: 80,
            dataIndex: 'delFlag',
            scopedSlots: { customRender: 'delFlag' }
          }
        ],
        // 数据集
        selectData: [],
        selectedRowKeys: [],
        selectedRows: [],
        url: {
          list: api.dataRuleList
        }
      }
    },
    computed: {

    },
    methods: {
      handleCancel() {
        this.visible = false;
      },
      handleOk() {
        this.selectData = this.selectedRowKeys;
        console.log("data:" + this.selectData);
        this.$emit("selectFinished", this.selectData);
        this.visible = false;
      },
      // 全选
      onSelectAll(selected, selectedRows, changeRows) {
        if (selected === true) {
          for (var a = 0; a < changeRows.length; a++) {
            this.selectData.push(changeRows[a]);
          }
        } else {
          for (var b = 0; b < changeRows.length; b++) {
            this.selectData.splice(this.selectData.indexOf(changeRows[b]), 1);
          }
        }
        // console.log(selected, selectedRows, changeRows);
      },
      onSelect(record, selected) {
        if (selected === true) {
          this.selectData.push(record);
        } else {
          var index = this.selectData.indexOf(record);
          if (index >= 0) {
            this.selectData.splice(this.selectData.indexOf(record), 1);
          }
        }
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectedRows;
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
